package org.kgc.alanhealth.util;



import java.util.HashMap;

public class Result extends HashMap<String,Object> {
    private static final long seriaVersionUID = 1L;
    public static  final  String CODE_TAG = "code";
    public static  final String MSG_TAG = "msg";
    public static final String DATA_TAG = "data";

    public Result(){

    }
    public Result(int code,String msg){
        super.put(CODE_TAG,code);
    }
    public Result(int code,String msg,Object date){
        this.put(CODE_TAG,code);
        this.put(MSG_TAG,msg);
        if(date!=null){
            super.put(DATA_TAG,date);
        }
        this.put(DATA_TAG,date);
    }
    //常用的 返回方法
    public static Result success(){
        return new Result(HttpStatus.SUCCESS,"操作成功");
    }
    public static Result success(Object date){
        return new Result(HttpStatus.SUCCESS,"操作成功",date);
    }
    public static Result success(String msg,Object data){
        return new Result(HttpStatus.SUCCESS,msg,data);
    }
    public static Result success(String msg){
        return Result.success(msg,null);
    }
    public static Result warn(String msg,Object data){
        return new Result(HttpStatus.WARN,msg,data);
    }
    public static Result warn(String msg){
        return Result.warn(msg,null);
    }
    public static Result error(){
        return Result.error("操作失败");
    }
    public static Result error(String msg){
        return Result.error(msg,null);
    }
    public static Result error(String msg,Object date){
        return new Result(HttpStatus.WARN,msg,date);
    }
    public static Result error(int code,String msg){
        return new Result(code,msg,null);
    }
    @Override
    public Result put(String key,Object value){
        super.put(key,value);
        return this;
    }


}